import { ElMessage } from 'element-plus'
import { deleteDictDataApi, deleteDictsApi, getDictDataApi, getDictsApi, putDictApi, putDictDataApi } from './api'
import { DictDataDTO, DictDTO } from './data'

export const getDicts = async (dto: DictDTO.Get) => {
  const { data } = await getDictsApi(dto)
  return data
}

export const putDict = async (dto: Pick<DictDTO.Put, 'id' | 'dictName' | 'dictType' | 'description'>) => {
  const { data } = await putDictApi(dto)
  ElMessage.success(dto.id ? '修改成功' : '添加成功')
  return data
}

export const deleteDict = async (dto: DictDTO.Delete) => {
  const { data } = await deleteDictsApi(dto)
  ElMessage.success('删除成功')
  return data
}

export const getDictData = async (dto: DictDataDTO.Get) => {
  const { data } = await getDictDataApi(dto)
  return data
}

export const putDictData = async (dto: DictDataDTO.Put) => {
  const { data } = await putDictDataApi(dto)
  ElMessage.success(dto.id ? '修改成功' : '添加成功')
  return data
}

export const deleteDictData = async (dto: DictDataDTO.Delete) => {
  const { data } = await deleteDictDataApi(dto)
  ElMessage.success('删除成功')
  return data
}
